package other_其他模式.service_locator_pattern_服务定位模式;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/10/14:21
 * @Description:
 */
public class ServiceLocator {

	private static Cache cache = new Cache();

	public static Service getService(String jndiName) {
		Service service = cache.getService(jndiName);
		if (service != null) {
			return service;
		}

		InitialContext initialContext = new InitialContext();
		service = ((Service) initialContext.lookup(jndiName));
		cache.addService(service);
		return service;
	}
}
